package Join;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class ReduceJoinDriver {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        try {
            Job job = Job.getInstance(conf);
            job.setJarByClass(ReduceJoinDriver.class);
            job.setMapperClass(ReduceJoinMapper.class);
            job.setReducerClass(ReduceJoinReducer.class);

            job.setMapOutputKeyClass(Text.class);
            job.setMapOutputValueClass(ReduceJoinBean.class);

            job.setOutputKeyClass(ReduceJoinBean.class);
            job.setOutputValueClass(NullWritable.class);

            FileInputFormat.setInputPaths(job,"D:\\MP\\Join\\input");
            Path path = new Path("D:\\MP\\Join\\output");
            if (path.getFileSystem(conf).exists(path)){
                path.getFileSystem(conf).delete(path,true);
            }
            FileOutputFormat.setOutputPath(job,path);
            System.exit(job.waitForCompletion(true)?0:1);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
